package com.bite.system.controller;

import com.bite.common.core.controller.BaseController;
import com.bite.common.core.domain.R;
import com.bite.system.domain.dto.SysUserSaveDTO;
import com.bite.system.domain.vo.SysUserVO;
import com.bite.system.service.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysUser")
@Tag(name = "管理员api")
public class SysController extends BaseController {
    @Autowired
    private ISysUserService userService;

    //返回登录成功还是失败了  boolean true false / int 0 1
    // 失败的原因是什么    String errMsg
    //请求方法  url
    //这里就需要接口文档了    统一的响应结构.




    //接口地址 /sysUser/login
    @Operation(summary="管理员登录",description = "根据账号密码进行管理员登录")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙,请稍后重试")
    @ApiResponse(responseCode = "3102",description = "用户不存在")
    @ApiResponse(responseCode = "3103",description = "用户名或密码错误")
    @PostMapping("/login")
    public R<String> login(@RequestBody SysUserSaveDTO sysUserSaveDTO ) {
        return userService.login(sysUserSaveDTO.getUserAccount(),sysUserSaveDTO.getPassword());
    }


    //管理员的增删改查

    //新增
    //请求地址   请求方法

    @Operation(summary="新增管理员",description = "根据提供的信息新增管理员")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙,请稍后重试")
    @ApiResponse(responseCode = "3101",description = "用户已存在")
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysUserSaveDTO  sysUserSaveDTO) {
        return toResult(userService.add(sysUserSaveDTO));
    }



    @DeleteMapping("/{userId}")
    @Operation(summary = "删除⽤⼾ ", description = " 通过⽤⼾id删除⽤⼾")
            @Parameters(value = {
                @Parameter(name = "userId", in = ParameterIn.PATH, description = "⽤⼾ID")
            })
    @ApiResponse(responseCode = "1000",description = "成功删除用户")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙,请稍后重试")
    @ApiResponse(responseCode = "3101",description = "用户不存在")
            public R<Void> delete(@PathVariable Long userId) {
        return null;
    }


    //查询用户
    @Operation(summary = "用户详情",description = "根据查询条件查询用户详情")
    @GetMapping("/detail")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.QUERY, description = "⽤⼾ID"),
            @Parameter(name = "sex", in = ParameterIn.QUERY, description = "用户性别")
    })

    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙,请稍后重试")
    @ApiResponse(responseCode = "3101",description = "用户不存在")
    public R<SysUserVO> detail(@RequestParam(required = true)Long userId, @RequestParam(required = false) String sex) {
        return null;
    }

}
